
#include "ui.hpp"

ioxx::Pin button_up_pin = BUTTON_UP_PIN_NUM;
ioxx::Pin button_down_pin = BUTTON_DOWN_PIN_NUM;
ioxx::Pin button_left_pin = BUTTON_LEFT_PIN_NUM;
ioxx::Pin button_right_pin = BUTTON_RIGHT_PIN_NUM;
ioxx::Pin button_ok_pin = BUTTON_OK_PIN_NUM;

ioxx::ButtonTrigger<ioxx::polarity::low> button_up;
ioxx::ButtonTrigger<ioxx::polarity::low> button_down;
ioxx::ButtonTrigger<ioxx::polarity::low> button_left;
ioxx::ButtonTrigger<ioxx::polarity::low> button_right;
ioxx::ButtonTrigger<ioxx::polarity::low> button_ok;


Blinker bkr;

beef::InterfaceBase *_last_screen = nullptr;


uint16_t slave_address = 25;


TimeType task_scan_button() {
    button_up.feed(button_up_pin.get());
    button_down.feed(button_down_pin.get());
    button_left.feed(button_left_pin.get());
    button_right.feed(button_right_pin.get());
    button_ok.feed(button_ok_pin.get());

    return 30;  // 每30毫秒扫描一次按键
}


void reset_buttons() {
    button_up.reset();
    button_down.reset();
    button_left.reset();
    button_right.reset();
    button_ok.reset();
}


void init_buttons() {
    pinMode(button_up_pin, INPUT_PULLUP);
    pinMode(button_down_pin, INPUT_PULLUP);
    pinMode(button_left_pin, INPUT_PULLUP);
    pinMode(button_right_pin, INPUT_PULLUP);
    pinMode(button_ok_pin, INPUT_PULLUP);
}